package apiSecurity;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 请求校验过滤器
 *
 * @author zhanglinfeng
 * @date create in 2023/7/27 16:15
 */
@WebFilter(urlPatterns = "/*")
public class ApiSecurityFilter implements Filter {
    /** 解密KEY */
    private final String key = "";
    @Override
    public void init(FilterConfig filterConfig) {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        ApiSecurityRequestWrapper requestWrapper = new ApiSecurityRequestWrapper(req);
        //TODO 校验接口
        //请求来源
        requestWrapper.getHeader("source");
        //请求时间戳
        requestWrapper.getHeader("timestamp");
        //签名
        requestWrapper.getHeader("sign");
        chain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {

    }
}
